/*
* @Author: zhangsai
* @Date: 2018/5/10
* @description: 信息状态
*/
<template>
  <div>
    <el-form label-width="120px">
      <el-form-item label="信息状态：">
        <el-dropdown trigger="click" @command="command">
          <el-button type="primary" plain>{{infoStatus | getNameById("infoStatus") || "请选择"}}<i class="el-icon-arrow-down el-icon--right"></i></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item 
              v-for="(item, i) in infoStatusList"
              :key="i"
              :command="item.dictValue" 
            >{{item.dictName}}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>
    </el-form>
    <el-dialog title="信息发布确认" :visible.sync="dialogStateVisible" width="30%" @close="close">
      <div class="dialog-main"><i class="el-icon-warning"></i>请您确定要发布这条信息？</div>
      <el-form :model="form" class="m-r-10" ref="validateForm">
        <el-form-item label="备注信息" prop="publishMessage" label-width="80px"
          :rules="[
            { required: true, message: '请输入备注信息', trigger: 'blur' }]"
        >
          <el-input v-model="form.publishMessage" 
                    auto-complete="off" 
                    type="textarea"
                    placeholder="请输入备注信息" 
                    :rows="4"></el-input>
        </el-form-item>  
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogStateVisible = false" round>取 消</el-button>
        <el-button type="primary" @click="submit" round>确 定</el-button>
      </div>
    </el-dialog>  
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { StateMessage } from '../../service/common/interface';
@Component
export default class DetailStateBtn extends Vue {
  @Prop({ default: '' })
  public infoStatus: string;
  // 初始化数据 相当于data
  public activeState = '';
  public dialogStateVisible = false;
  public form: {publishMessage: string} = { publishMessage: '' };
  public infoStatusList = this.$store.state.user.dictionary.dicList.infoStatus;
  // refs
  public $refs: {
    validateForm: HTMLFormElement
  };

  public command(command: string) {
    this.dialogStateVisible = true;
    this.activeState = command;
  }
  public getEnable(infoStatus: string) {
    const infoStatusList = infoStatus.split('');
    return {
      enableClick: infoStatusList[0] === '1' ? '1' : '2',
      enableCount: infoStatusList[1] === '1' ? '1' : '2',
      enableSearch: infoStatusList[2] === '1' ? '1' : '2',
      enableQuote: infoStatusList[3] === '1' ? '1' : '2',
    };
  }
  public submit() {
    this.$refs.validateForm.validate((valid: boolean) => {
      if (valid) {
          const parame: StateMessage = Object.assign( {} as StateMessage, {
            publishMessage: this.form.publishMessage,
            infoStatus: this.activeState,
          }, this.getEnable(this.activeState));
          this.$emit('setState', parame);
          this.dialogStateVisible = false;
      }
    });
  }
  public close() {
    this.$refs.validateForm.resetFields();
  }
  
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.dialog-main{
  font-size:14px;
  margin-bottom:20px;
}
.dialog-main i{
  margin:0 10px 0 0;
}
</style>
